<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
    x:Class="OpenLS.Spreadsheet.UI.WorksheetPageResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI"
    xmlns:drawingui="http://schemas.Kherty.com/office/2007/drawing"
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals"
    xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:UI="clr-namespace:OpenLS.Chart.UI;assembly=OpenLS.Chart.UI" xmlns:UI1="clr-namespace:OpenLS.UI;assembly=OpenLS.UI" xmlns:Spreadsheet="clr-namespace:OpenLS.Spreadsheet;assembly=OpenLS.Spreadsheet">
    <ResourceDictionary.MergedDictionaries>
        <ssui:WorksheetDrawingResources></ssui:WorksheetDrawingResources>
        <UI:ChartResources></UI:ChartResources>
    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="drawingContainerStyle" TargetType="{x:Type FrameworkElement}" >
        <Setter Property="ssui:WorksheetGrid.Row" Value="{Binding Path=Cell.Row}"/>
        <Setter Property="ssui:WorksheetGrid.Column" Value="{Binding Path=Cell.Column}"/>
        <Setter Property="ssui:WorksheetGrid.ItemWidth" Value="{Binding ActualWidth}"/>
        <Setter Property="ssui:WorksheetGrid.ItemHeight" Value="{Binding ActualHeight}"/>
        <Setter Property="ssui:WorksheetGrid.RowOffset" Value="{Binding RowOffset}"/>
        <Setter Property="ssui:WorksheetGrid.ColumnOffset" Value="{Binding ColumnOffset}"/>
    </Style>

    <System:Double x:Key="zero">0</System:Double>
    <Style TargetType="{x:Type TextBlock}" x:Key="dimensionTextBlockStyle">
        <Setter Property="HorizontalAlignment" Value="Center"></Setter>
        <Setter Property="VerticalAlignment" Value="Center"></Setter>
        <Setter Property="Text" Value="{Binding Label}"></Setter>
    </Style>
    <DataTemplate DataType="{x:Type Spreadsheet:Row}">
        <Border Height="{Binding ActualHeight}" >
            <Border BorderBrush="Black" BorderThickness="1 0 1 1" Margin="0 0 0 -1">
                <TextBlock  Style="{StaticResource dimensionTextBlockStyle}"></TextBlock>
            </Border>
        </Border>
    </DataTemplate>
    <DataTemplate DataType="{x:Type Spreadsheet:Column}">
        <Border Width="{Binding ActualWidth}">
            <Border BorderBrush="Black" BorderThickness="0 1 1 1"  Margin="0 0 -1 0">
                <TextBlock  Style="{StaticResource dimensionTextBlockStyle}"></TextBlock>
            </Border>
        </Border>
    </DataTemplate>
    <DataTemplate x:Key="ActualFooterHeader" >
        <Grid TextElement.FontFamily="{Binding Path=FontFamily}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="{Binding LeftText}" HorizontalAlignment="Left"  TextWrapping="Wrap"></TextBlock>
            <TextBlock Text="{Binding CenterText}" Grid.Column="1" HorizontalAlignment="Center" TextWrapping="Wrap"></TextBlock>
            <TextBlock Text="{Binding RightText}" Grid.Column="2" HorizontalAlignment="Right"  TextWrapping="Wrap"></TextBlock>
        </Grid>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ssui:WorksheetPage}">
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Name="pageGrid"
                ssui:SpreadsheetElement.ColorMode="GrayScale" ssui:SpreadsheetElement.WorksheetFragment="{Binding}"
              drawingui:DrawingElement.Theme="{Binding Worksheet.Workbook.Theme}"
              drawingui:DrawingElement.ColorScheme ="{Binding Worksheet.Workbook.Theme.ColorScheme}" 
              
              >
            <Grid.Margin>
                <MultiBinding Mode="OneWay">
                    <MultiBinding.Converter>
                        <Internals:IntToThicknessConverter />
                    </MultiBinding.Converter>
                    <Binding Path="Worksheet.PageMargins.Left" FallbackValue="{StaticResource zero}" />
                    <Binding Path="Worksheet.PageMargins.Header" FallbackValue="{StaticResource zero}"/>
                    <Binding Path="Worksheet.PageMargins.Right" FallbackValue="{StaticResource zero}"/>
                    <Binding Path="Worksheet.PageMargins.Footer" FallbackValue="{StaticResource zero}"/>
                </MultiBinding>
            </Grid.Margin>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>
            <ContentControl Height="{Binding Worksheet.PageMargins.Top}" Content="{Binding ActualHeader}" ContentTemplate="{StaticResource ActualFooterHeader}"></ContentControl>
            <ContentControl Height="{Binding Worksheet.PageMargins.Bottom}" Content="{Binding ActualFooter}" Grid.Row="2"  ContentTemplate="{StaticResource ActualFooterHeader}"></ContentControl>
            <Grid Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top">

                <Grid.LayoutTransform>
                    <ScaleTransform x:Name="scaleTransform"  ScaleX="{Binding Path=Worksheet.PageSetup.Scale, Converter={x:Static Internals:SpreadsheetConverters.FromPercentConverter}}"
                        ScaleY="{Binding Path=Worksheet.PageSetup.Scale, Converter={x:Static Internals:SpreadsheetConverters.FromPercentConverter}}"/>

                </Grid.LayoutTransform>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Border Name="topLeft" Visibility="Collapsed">
                    <Border BorderBrush="Black" BorderThickness="1 1 1 1" ></Border>
                </Border>
                <ItemsControl TextElement.FontFamily="{Binding Path=Worksheet.Workbook.Theme.FontScheme.MinorFont.Latin}" ItemsSource="{Binding Rows}" Grid.Row="1" Name="rows" Visibility="Collapsed">
                </ItemsControl>
                <ItemsControl  TextElement.FontFamily="{Binding Path=Worksheet.Workbook.Theme.FontScheme.MinorFont.Latin}" ItemsSource="{Binding Columns}" Grid.Column="1" Name="columns" Visibility="Collapsed">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel Orientation="Horizontal"></VirtualizingStackPanel>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
                <Grid Name="cells" Grid.Row="1" Grid.Column="1" Height="{Binding DesiredHeight}" Width="{Binding DesiredWidth}">
                    <Grid Name="grid4">
                        <Grid.Background>
                            <ImageBrush x:Name="imageBrush" TileMode="Tile"  Stretch="None" ImageSource="{Binding Path=Worksheet.Background}"
                      Viewport="{Binding Path=Worksheet.BackgroundViewport}" ViewportUnits="Absolute"/>
                        </Grid.Background>
                    </Grid>
                    <ssui:GridLineControl WorksheetFragment="{Binding}" x:Name="gridLines"  Visibility="Hidden" LineBrush="{DynamicResource {x:Static ssui:SpreadsheetBrushes.GridLineBrushKey}}"/>
                    <Internals:CellBackgroundControl WorksheetPane="{Binding}" Focusable="False" ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawingui:DrawingElement.ColorScheme)}"/>
                    <Internals:CellSparkLineControl WorksheetPane="{Binding}" Focusable="False" ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawingui:DrawingElement.ColorScheme)}"/>
                    <Internals:CellBordersControl WorksheetPane="{Binding}" Focusable="False" ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawingui:DrawingElement.ColorScheme)}"/>
                    <Internals:ClusteredCellTextControl WorksheetPane="{Binding}" Focusable="False"  x:Name="cellTextControl" ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawingui:DrawingElement.ColorScheme)}"/>
                    <ItemsControl ItemsSource="{Binding Worksheet.Anchors}" Focusable="False" x:Name="anchors"  Background ="{x:Null}" Cursor="{x:Static Cursors.Arrow}"
                 ItemContainerStyle="{StaticResource drawingContainerStyle}" ClipToBounds="True" DataContext="{Binding}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ssui:WorksheetGrid x:Name="drawings"
                Cursor="{x:Static Cursors.Arrow}"
                Background="{x:Null}"
                Top="{Binding Path=Top, Mode=TwoWay}"
                Left="{Binding Path=Left, Mode=TwoWay}"
                Columns="{Binding Path=Worksheet.Columns}"
                Rows="{Binding Path=Worksheet.Rows}"/>

                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </Grid>
            </Grid>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Worksheet.PageSetup.BlackAndWhite}" Value="True">
                <Setter TargetName="pageGrid" Property="ssui:SpreadsheetElement.ColorMode" Value="BlackAndWhite"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Worksheet.PrintOptions.GridLinesVisible}" Value="True">
                <Setter TargetName="gridLines" Property="Visibility" Value="Visible"></Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding Worksheet.PrintOptions.RowColumnHeadersVisible}" Value="True">
                <Setter TargetName="rows" Property="Visibility" Value="Visible"></Setter>
                <Setter TargetName="columns" Property="Visibility" Value="Visible"></Setter>
                <Setter TargetName="topLeft" Property="Visibility" Value="Visible"></Setter>
            </DataTrigger>
            <!-- <DataTrigger Binding="{Binding Worksheet.Properties.PageSetupProperties.FitToPage}" Value="True">
                <Setter TargetName="pageGrid" Property="LayoutTransform">
                    <Setter.Value>
                        <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform>
                    </Setter.Value>
                </Setter>
            </DataTrigger> -->
        </DataTemplate.Triggers>
    </DataTemplate>

</ResourceDictionary>